//
//  ForgetPasswordFromView.m
//  Gxj
//
//  Created by 刘伟 on 2017/9/16.
//  Copyright © 2017年 wkq. All rights reserved.
//

#import "ForgetPasswordFromView.h"

@implementation ForgetPasswordFromView

- (instancetype)initWithFrame:(CGRect)frame
{
    if (self = [super initWithFrame:frame])
    {
        self.backgroundColor = [UIColor whiteColor];
        [self addSubview:self.userNum];
        [self addSubview:self.verification];
        [self addSubview:self.userPassWord];
        [self addSubview:self.confirmPassword];
        [self addSubview:self.sendVerification];
        [self addSubview:self.commit];
        [self showForgetPassword];
    }
    return self;
}

- (void)showForgetPassword
{
    _userNum.sd_layout
    .topSpaceToView(self,kHeightScale(80))
    .leftSpaceToView(self,kWidthScale(15))
    .rightSpaceToView(self,kWidthScale(15))
    .heightIs(kHeightScale(44));
    
    _sendVerification.sd_layout
    .topSpaceToView(self.userNum,kHeightScale(15))
    .rightEqualToView(self.userNum)
    .widthIs(kWidthScale(93))
    .heightIs(kHeightScale(44));
    
    _verification.sd_layout
    .topSpaceToView(self.userNum,kHeightScale(15))
    .leftEqualToView(self.userNum)
    .rightSpaceToView(self.sendVerification,kWidthScale(15))
    .heightIs(kHeightScale(44));
    
    _userPassWord.sd_layout
    .topSpaceToView(self.verification,kHeightScale(15))
    .leftEqualToView(self.userNum)
    .rightEqualToView(self.userNum)
    .heightIs(kHeightScale(44));
    
    _confirmPassword.sd_layout
    .topSpaceToView(self.userPassWord,kHeightScale(15))
    .leftEqualToView(self.userPassWord)
    .rightEqualToView(self.userPassWord)
    .heightIs(kHeightScale(44));
    
    _commit.sd_layout
    .topSpaceToView(self.confirmPassword,kHeightScale(15))
    .leftEqualToView(self.confirmPassword)
    .rightEqualToView(self.confirmPassword)
    .heightIs(kHeightScale(40));
}

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

- (UITextField *)userNum
{
    if (!_userNum)
    {
        _userNum = [[UITextField alloc] init];
        _userNum.layer.borderWidth = 1;
        _userNum.layer.borderColor = [UIColor lightGrayColor].CGColor;
        _userNum.leftView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, kWidthScale(10), kHeightScale(44))];
        _userNum.leftViewMode = UITextFieldViewModeAlways;
        _userNum.layer.cornerRadius = kWidthScale(8);
        _userNum.layer.masksToBounds = YES;
        _userNum.clearButtonMode = UITextFieldViewModeWhileEditing;
        _userNum.placeholder = @"请输入手机号";
        _userNum.keyboardType = UIKeyboardTypeNumberPad;
        _userNum.tag = 300000;
    }
    return _userNum;
}

- (UITextField *)verification
{
    if (!_verification)
    {
        _verification = [[UITextField alloc] init];
        _verification.layer.borderWidth = 1;
        _verification.layer.borderColor = [UIColor lightGrayColor].CGColor;
        _verification.leftView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, kWidthScale(10), kHeightScale(44))];
        _verification.leftViewMode = UITextFieldViewModeAlways;
        _verification.layer.cornerRadius = kWidthScale(8);
        _verification.layer.masksToBounds = YES;
        _verification.clearButtonMode = UITextFieldViewModeWhileEditing;
        _verification.placeholder = @"请输入短信验证码";
        _verification.keyboardType = UIKeyboardTypeNumberPad;
        _verification.tag = 300001;
    }
    return _verification;
}

- (UITextField *)userPassWord
{
    if (!_userPassWord)
    {
        _userPassWord = [[UITextField alloc] init];
        _userPassWord.layer.borderWidth = 1;
        _userPassWord.layer.borderColor = [UIColor lightGrayColor].CGColor;
        _userPassWord.leftView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, kWidthScale(10), kHeightScale(44))];
        _userPassWord.leftViewMode = UITextFieldViewModeAlways;
        _userPassWord.layer.cornerRadius = kWidthScale(8);
        _userPassWord.layer.masksToBounds = YES;
        _userPassWord.clearButtonMode = UITextFieldViewModeWhileEditing;
        _userPassWord.placeholder = @"请输入密码，6-13位英文字母或数字";
        _userPassWord.secureTextEntry = YES;
        _userPassWord.tag = 300002;
    }
    return _userPassWord;
}

- (UITextField *)confirmPassword
{
    if (!_confirmPassword)
    {
        _confirmPassword = [[UITextField alloc] init];
        _confirmPassword.layer.borderWidth = 1;
        _confirmPassword.layer.borderColor = [UIColor lightGrayColor].CGColor;
        _confirmPassword.leftView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, kWidthScale(10), kHeightScale(44))];
        _confirmPassword.leftViewMode = UITextFieldViewModeAlways;
        _confirmPassword.layer.cornerRadius = kWidthScale(8);
        _confirmPassword.layer.masksToBounds = YES;
        _confirmPassword.clearButtonMode = UITextFieldViewModeWhileEditing;
        _confirmPassword.placeholder = @"请再次确认密码，6-13位英文字母或数字";
        _confirmPassword.secureTextEntry = YES;
        _confirmPassword.tag = 300003;
    }
    return _confirmPassword;
}

- (UIButton *)sendVerification
{
    if (!_sendVerification)
    {
        _sendVerification = [UIButton buttonWithType:UIButtonTypeCustom];
        [_sendVerification setTitle:@"发送验证码" forState:0];
        [_sendVerification setBackgroundImage:[UIImage imageNamed:@"bg"] forState:0];
        [_sendVerification setTitleColor:[UIColor whiteColor] forState:0];
        _sendVerification.layer.cornerRadius = kWidthScale(12);
        _sendVerification.layer.masksToBounds = YES;
        _sendVerification.titleLabel.font = [UIFont systemFontOfSize:kWidthScale(13)];
    }
    return _sendVerification;
}

- (UIButton *)commit
{
    if (!_commit)
    {
        _commit = [UIButton buttonWithType:UIButtonTypeCustom];
        [_commit setTitle:@"提交" forState:0];
        [_commit setBackgroundImage:[UIImage imageNamed:@"bg"] forState:0];
        [_commit setTitleColor:[UIColor whiteColor] forState:0];
        _commit.layer.cornerRadius = kWidthScale(12);
        _commit.layer.masksToBounds = YES;
    }
    return _commit;
}

@end
